package co.crossoft.exposeServiceImpl;

import co.crossoft.base.common.JsonResult;
import co.crossoft.daoImpl.ResourceDaoImpl;
import co.crossoft.domain.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import co.crossoft.service.ExposeResourceService;

/**
 * Created by Snow on 8/22/2017.
 */

@Component
public class ExposeResourceServiceImpl implements ExposeResourceService {

    @Autowired
    ResourceDaoImpl resourceDaoImpl;

    /**
     * @param plant    工厂
     * @param resource 资源 模糊查询
     * @return
     */
    @Override
    public JsonResult resourceList(String plant, String resource) {
        return resourceDaoImpl.getResourceList(plant, resource);
    }

    /**
     * @param plant       工厂
     * @param resource    资源
     * @param description 描述
     * @param statusFk    状态外键
     * @param dateEffect  生效日期
     * @param dateExpires 失效日期
     * @return
     */
    @Override
    public JsonResult updateOrAddResource(String plant, String resource, String description, String statusFk, String dateEffect, String dateExpires) {
        Resource resourceBean = new Resource();
        resourceBean.setHandle("RESOURCE:" + plant + "," + resource);
        resourceBean.setDateEffect(dateEffect);
        resourceBean.setDateExpire(dateExpires);
        resourceBean.setDescription(description);
        resourceBean.setPlant(plant);
        resourceBean.setResource(resource);
        resourceBean.setStatusFk(statusFk);
        return resourceDaoImpl.addOrUpdateResource(resourceBean);
    }

    /**
     * @param handle 资源主键
     * @return
     */
    @Override
    public JsonResult deleteResource(String handle) {
        return resourceDaoImpl.deleteResource(handle);
    }

    /**
     * @param handle 主键
     * @return
     */
    @Override
    public JsonResult selectOneResourceByHandle(String handle) {
        return resourceDaoImpl.selectOneResource(handle);
    }
}
